package com.easemob.chatui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.easemob.chat.EMGroup;
import com.easemob.chat.EMGroupManager;
import com.easemob.chatui.Constant;
import com.easemob.chatui.domain.User;
import com.lyw.GeoLocationClient.App;
import com.lyw.GeoLocationClient.R;

import java.util.ArrayList;
import java.util.List;

public class ContactManagerActivity extends BaseActivity {

    @Bind(R.id.select_contact)
    TextView selectContact;
    @Bind(R.id.select_group)
    TextView selectGroup;
    @Bind(R.id.container)
    FrameLayout mContainer;

    GroupsFragment groupListFragmet;
    ContactlistFragment contactListFragment;

    private int curPage = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_picker);
        ButterKnife.bind(this);

        initContacts();
        initGroups();

        initFragments();
    }

    protected void initFragments() {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, groupListFragmet)
                .add(R.id.container, contactListFragment)
                .hide(groupListFragmet)
                .show(contactListFragment).commit();
    }

    protected void initContacts() {
        contactListFragment = new ContactlistFragment();
    }

    protected void initGroups() {
        groupListFragmet = new GroupsFragment();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    private void switchTab() {
        if (curPage == 0) {
            curPage = 1;
        } else {
            curPage = 0;
        }

        if (curPage == 0) {
            selectContact.setTextColor(getResources().getColor(R.color.white));
            selectGroup.setTextColor(getResources().getColor(R.color.gray_normal));
            getSupportFragmentManager().beginTransaction().hide(groupListFragmet).show(contactListFragment).commit();
        } else {

            selectContact.setTextColor(getResources().getColor(R.color.gray_normal));
            selectGroup.setTextColor(getResources().getColor(R.color.white));
            getSupportFragmentManager().beginTransaction().hide(contactListFragment).show(groupListFragmet).commit();
        }
    }

    @OnClick(R.id.select_contact)
    void onContactTabClick() {
        if (curPage == 0) {
            return;
        }
        switchTab();
    }

    @OnClick(R.id.select_group)
    void onGroupTabClick() {
        if (curPage == 1) {
            return;
        }
        switchTab();
    }



}
